package com.ulwx.test;


import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class MyClass {

	// create a static client as most installs only need
	// a single instance
	protected static MemCachedClient mcc = new MemCachedClient();

	// set up connection pool once at class load
	static {

		// server list and weights
		String[] servers =
			{
			  "server1.mydomain.com:1624",
			  "server2.mydomain.com:1624",
			  "server3.mydomain.com:1624"
			};

		Integer[] weights = { 3, 3, 2 };

		// grab an instance of our connection pool
		SockIOPool pool = SockIOPool.getInstance();

		// set the servers and the weights
		pool.setServers( servers );
		pool.setWeights( weights );

		// set some TCP settings
		// disable nagle
		// set the read timeout to 3 secs
		// and don't set a connect timeout
		pool.setHashingAlg(SockIOPool.CONSISTENT_HASH);
		pool.setNagle( false );
		pool.setSocketTO( 3000 );
		
		pool.setSocketConnectTO( 0 );

		// initialize the connection pool
		pool.initialize();
	}

	// from here on down, you can call any of the client calls
	public static void examples() {
        mcc.set( "foo", "This is a test String" );
		String bar = mcc.get( "foo" ).toString();
	}
}